/*
 * Copyright (c) 2012 Universidad Antonio de Nebrija.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Apache License v2.0
 * which accompanies this distribution, and is available at
 * http://www.apache.org/licenses/LICENSE-2.0.html
 * 
 * Contributors:
 *    Universidad Antonio de Nebrija - initial API, implementation and documentation
 */
package com.nebrija.riif.model;

import java.util.ArrayList;
import java.util.Set;

/**
 * Represents the parameter token
 * Needs some extra modifications to represent the input/output stuff defined in environment
 * @author asanchep
 *
 */
public class Parameter extends RIIFProperties{

	/** type of parameter: input/output or none of them*/
	private ParameterType type = ParameterType.NONE;
	/** Enumeration type defined in the grammar file for an input/output parameter */
	private EnumType enums; //TODO make it work when the RIIF grammar is fixed

	/**
	 * Creates a parameter
	 * @param name the name of the parameter
	 */
	public Parameter(String name) {
		super(name);
	}
	
	/**
	 * Creates a parameter
	 * @param name the name of the parameter
	 * @param type the type of the parameter (input/output or none of them)
	 * @param currentValue the current value of this parameter (if an enumeration type is defined)
	 * @param values the available values of the parameter if an enumeration type is defined
	 */
	public Parameter(String name, ParameterType type, String currentValue, String... values) {
		super(name);
		this.type=type;
		this.enums = new EnumType(currentValue, values);
	}
	
	@Override
	public String toString() {
		if(type==ParameterType.NONE){
			return super.toString();
		}
		StringBuffer str = new StringBuffer (name);
		str.append("\n");
		Set<String> keys = props.keySet();
		for (String key: keys){
			str.append("\t->").append(key)
				.append(":").append(props.get(key)).append("\n");
		}
		
		keys = assertions.keySet();
		for (String key: keys){
			str.append("\t->").append(key);
			str.append("\n");
			ArrayList<AssertValidation> vals = assertions.get(key);
			for (int i=0; i<vals.size();i++){
				str.append("\t").append(vals.get(i)).append("\n");
			}
		}		
		return str.toString();
	}

	/**
	 * Getter for the parameter type
	 * @return the parameter type (input/output or none of them)
	 */
	public ParameterType getType() {
		return type;
	}
	
	public void setType(ParameterType type) {
		this.type = type;
	}

	/**
	 * Getter for the possible values and the current value if the parameter has an enum type
	 * @return the possible and current value grouped in an EnumType object
	 */
	public EnumType getEnums() {
		return enums;
	}

}
